<template>
	<view>
		<uLine></uLine>
		<view class="list">

			<!-- 左侧 -->
			<scroll-view scroll-y="true" class="list-left" :style="computedClassObject">
				<view v-for="(item,i) in leftItemData" :key="i" class="left-item" @tap="leftItemClicked(i,item.id)">
					<view class="left-name" :class="activeIndex === i ? 'left-name-active' : ''">
						{{item.name}}
					</view>
				</view>
			</scroll-view>

			<!-- 右侧 -->
			<scroll-view scroll-y="true" class="list-right" :style="computedClassObject">
				<view class="right-list">
					<block v-for="(item,index) in rightItemData" :key="index">
						<view class="list-title">
							{{item.name}}
						</view>
						<view class="right-content">
							<view class="right-item" v-for="(val,idx) in item.list" :key="idx">
								<image :src="val.imgUrl" class="right-img"></image>
								<view class="right-name">
									{{val.name}}
								</view>
							</view>
						</view>
					</block>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import $http from '@/common/api/request.js'
	import uLine from '@/components/common/Line.vue'
	export default {
		data() {
			return {
				clientHeight: 0,
				activeIndex: 0,
				leftItemData: [],
				rightItemData: [],
			}
		},
		onLoad() {
			this.getData(this.activeIndex + 1)
		},
		onNavigationBarSearchInputClicked() {
			uni.navigateTo({
				url: "/pages/search/search"
			})
		},
		// 获取可视区域高度 windowHeight
		onReady() {
			uni.getSystemInfo({
				success: (res) => {
					this.clientHeight = res.windowHeight
				}
			})
		},
		methods: {
			leftItemClicked(index, id) {
				this.activeIndex = index
				this.getData(id)
			},
			// id从1开始，index从0开始
			getData(currId) {
				let res = [{
						id: 1,
						name: "家居家纺",
						data: [{
								name: "家纺",
								list: [{
										id: 1,
										name: "毛巾/浴巾",
										imgUrl: "/static/img/product1.jpg"
									},
									{
										id: 2,
										name: "枕头",
										imgUrl: "/static/img/product2.jpg"
									},
									{
										id: 3,
										name: "床单",
										imgUrl: "/static/img/product3.jpg"
									}
								]
							},
							{
								name: "生活用品",
								list: [{
										id: 1,
										name: "牙刷",
										imgUrl: "/static/img/product4.jpg"
									},
									{
										id: 2,
										name: "纸巾",
										imgUrl: "/static/img/product5.jpg"
									},
									{
										id: 3,
										name: "电热水壶",
										imgUrl: "/static/img/product6.jpg"
									}
								]
							}
						]
					},
					{
						id: 2,
						name: "女装",
						data: [{
								name: "裙装",
								list: [{
										id: 1,
										name: "半身裙",
										imgUrl: "/static/img/product1.jpg"
									},
									{
										id: 2,
										name: "连衣裙",
										imgUrl: "/static/img/product2.jpg"
									},
									{
										id: 3,
										name: "吊带裙",
										imgUrl: "/static/img/product3.jpg"
									}
								]
							},
							{
								name: "上衣",
								list: [{
										id: 1,
										name: "打底衫",
										imgUrl: "/static/img/product4.jpg"
									},
									{
										id: 2,
										name: "衬衫",
										imgUrl: "/static/img/product5.jpg"
									},
									{
										id: 3,
										name: "针织衫",
										imgUrl: "/static/img/product6.jpg"
									}
								]
							}
						]
					},
					{
						id: 3,
						name: "男装",
						data: [{
								name: "上衣",
								list: [{
										id: 1,
										name: "半身裙",
										imgUrl: "/static/img/product1.jpg"
									},
									{
										id: 2,
										name: "连衣裙",
										imgUrl: "/static/img/product2.jpg"
									},
									{
										id: 3,
										name: "吊带裙",
										imgUrl: "/static/img/product3.jpg"
									}
								]
							},
							{
								name: "裤装",
								list: [{
										id: 1,
										name: "打底衫",
										imgUrl: "/static/img/product4.jpg"
									},
									{
										id: 2,
										name: "衬衫",
										imgUrl: "/static/img/product5.jpg"
									},
									{
										id: 3,
										name: "针织衫",
										imgUrl: "/static/img/product6.jpg"
									}
								]
							}
						]
					}
				]
				let leftItemData = [],
					rightItemData = []
				res.forEach(el => {
					leftItemData.push({
						id: el.id,
						name: el.name
					})
					if (el.id == currId) {
						rightItemData = [...el.data]
					}
				})
				this.leftItemData = leftItemData
				this.rightItemData = rightItemData
			}
		},
		components: {
			uLine
		},
		computed: {
			computedClassObject() {
				return `height: ${this.clientHeight}px;`
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		display: flex;

		.list-left {
			width: 200rpx;

			.left-item {
				border-bottom: 2rpx solid #fff;
				font-size: 28rpx;
				background-color: #f7f7f7;
				font-weight: bold;

				.left-name {
					padding: 24rpx 6rpx;
					text-align: center;
				}

				.left-name-active {
					border-left: 8rpx solid #49bdfb;
					background-color: #fff;
				}
			}
		}

		.list-right {
			flex: 1;
			padding: 0 20rpx;

			.right-list {
				.list-title {
					font-weight: bold;
					padding: 30rpx 0;
				}

				.right-content {
					display: flex;
					flex-wrap: wrap;

					.right-item {
						width: 150rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						padding: 10rpx;

						.right-img {
							width: 150rpx;
							height: 150rpx;
							border-radius: 10rpx;
						}

						.right-name {
							padding: 16rpx 0;
						}
					}
				}
			}
		}
	}
</style>